package com.java.agent.enhance;

import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

public abstract class BaseEnhance {
    @RuntimeType
    public Object intercept(@AllArguments Object[] allArguments,
                            @SuperCall Callable<?> callable,//                      被拦截的原始方法
                            @Origin Method method) throws Exception {
        Object ret = null;
        try {
            doSomeThing(allArguments);
            ret = callable.call();
        }finally {
            ret = postDoSomThing(allArguments,callable,method,ret);
            return ret;
        }
    }

    public abstract Object doSomeThing(Object[] allArguments);

    public abstract Object postDoSomThing(Object[] allArguments, Callable<?> callable, Method method, Object ret);
}
